package com.hwadee.backend.entity.HealthRecord;

import lombok.Getter;
import lombok.Setter;

import java.sql.Date;

@Setter
@Getter
public class HealthIndicators extends HealthRecord {
    // 身高 cm
    private double height;
    // 体重 kg
    private double weight;
    // BMI 指数
    private double bmi;
    // 血压
    private String bloodPressure;
    // 血糖
    private String bloodSugar;
    // 心率
    private String heartRate;
    // 备注
    private String remarks;

    public HealthIndicators() {
    }

    public HealthIndicators(int recordId, Date recordDate, String recordType, String detail) {
        super(recordId, recordDate, recordType, detail);
        splitDetail(detail);
        super.setDetail(null); // 将 detail 置为空值
    }

    /**
     * 从 detail 字符串中解析身高、体重、BMI 指数、血压、血糖、心率和备注数据
     * @param detail 包含身高、体重、BMI 指数、血压、血糖、心率和备注的字符串，用 | 分隔
     */
    private void splitDetail(String detail) {
        String[] parts = detail.split("\\|");
        try {
            if (parts.length >= 1) {
                this.height = Double.parseDouble(parts[0]);
            }
            if (parts.length >= 2) {
                this.weight = Double.parseDouble(parts[1]);
            }
            if (parts.length >= 3) {
                this.bmi = Double.parseDouble(parts[2]);
            }
        } catch (NumberFormatException e) {
            // 处理转换失败的情况，可根据需求扩展日志记录等操作
            this.height = 0;
            this.weight = 0;
            this.bmi = 0;
        }
        if (parts.length >= 4) {
            this.bloodPressure = parts[3];
        }
        if (parts.length >= 5) {
            this.bloodSugar = parts[4];
        }
        if (parts.length >= 6) {
            this.heartRate = parts[5];
        }
        if (parts.length >= 7) {
            this.remarks = parts[6];
        }
    }

}